/**
 * User数据传输对象
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.dto;


import com.sxf.crm.entity.Department;
import com.sxf.crm.entity.User;
import com.sxf.crm.enums.CustomerStatus;
import com.sxf.crm.enums.EnableStatus;

import lombok.Data;

/**
 * 用户数据传输对象
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/6/1
 */
@Data
public class UserDTO {
    private Long id;
    private String username;
    private String realName;
    private String email;
    private String phoneNumber;
    private Long departmentId;
    private String departmentName;
    private String position;
    private Integer status;
    private String statusLabel;
    private String avatarUrl;
    private Long lastLoginTime;
    private Long createAt;
    private Long createUserId;
    private String creatorName;
    private Long updateAt;
    private Long updateUserId;
    private String updaterName;

    public static UserDTO fromEntity(User user) {
        if (user == null) {
            return null;
        }

        UserDTO dto = new UserDTO();
        dto.setId(user.getId());
        dto.setUsername(user.getUsername());
        dto.setRealName(user.getRealName());
        dto.setEmail(user.getEmail());
        dto.setPhoneNumber(user.getPhoneNumber());
        dto.setPosition(user.getPosition());
        dto.setStatus(user.getStatus());
        dto.setStatusLabel(EnableStatus.fromValue(user.getStatus()).getDescription());
        dto.setAvatarUrl(user.getAvatarUrl());            // 设置主要部门信息

        dto.setLastLoginTime(user.getLastLoginTime());
        dto.setCreateAt(user.getCreateAt());
        dto.setCreateUserId(user.getCreateUserId());
        dto.setUpdateAt(user.getUpdateAt());
        dto.setUpdateUserId(user.getUpdateUserId());
        
        return dto;
    }
} 